home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / TSR / TSRSRC35 / EMS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-21  |  5KB  |  198 lines

  1. {**************************************************************************
  2. *   EMS - unit of EMS functions                                           *
  3. *   Copyright (c) 1991,1993 Kim Kokkonen, TurboPower Software.            *
  4. *   May be freely distributed and used but not sold except by permission. *
  5. *                                                                         *
  6. *   Version 3.0 9/24/91                                                   *
  7. *     first release                                                       *
  8. *   Version 3.1 11/4/91                                                   *
  9. *     no change                                                           *
  10. *   Version 3.2 11/22/91                                                  *
  11. *     no change                                                           *
  12. *   Version 3.3 1/8/92                                                    *
  13. *     no change                                                           *
  14. *   Version 3.4 2/14/92                                                   *
  15. *     no change                                                           *
  16. *   Version 3.5 10/18/93                                                  *
  17. *     add RestorePageMap function                                         *
  18. *     change FreeEms to return a Byte status code                         *
  19. ***************************************************************************}
  20.  
  21. {$R-,S-,I-,V-,B-,F-,A-,E-,N-,G-,X-}
  22.  
  23. unit Ems;
  24.   {-EMS functions needed for MAPMEM, MARKNET, RELNET}
  25.  
  26. interface
  27.  
  28. const
  29.   MaxHandles = 255;
  30.   EmsDevice : string[8] = 'EMMXXXX0';
  31. type
  32.   HandlePageRecord =
  33.   record
  34.     Handle : Word;
  35.     NumPages : Word;
  36.   end;
  37.   PageArray = array[1..MaxHandles] of HandlePageRecord;
  38.   PageArrayPtr = ^PageArray;
  39.  
  40. function EmsPresent : Boolean;
  41.   {-Return true if EMS memory manager is present}
  42.  
  43. function EmsPagesAvailable : LongInt;
  44.   {-Return Total pages in high word, Available pages in low word}
  45.  
  46. function EmsHandles(var PageMap : PageArray) : Word;
  47.   {-Return number of handles allocated and page map}
  48.  
  49. function EmsVersion : Byte;
  50.   {-Return EMM version number}
  51.  
  52. procedure GetHandleName(Handle : Word; var Name : String);
  53.   {-Return name of EMS block, if any}
  54.  
  55. function FreeEms(Handle : Word) : Byte;
  56.   {-Deallocate EMS handle}
  57.  
  58. function RestorePageMap(Handle : Word) : Byte;
  59.   {-Restore page map}
  60.  
  61.   {=========================================================================}
  62.  
  63. implementation
  64.  
  65.   function EMSpresent : Boolean; assembler;
  66.     {-Return true if EMS memory manager is present}
  67.   asm
  68.     mov ax,$3567
  69.     int $21
  70.     mov ax,es
  71.     or ax,bx            {is int $67 nil?}
  72.     jz @AbsentNoClose
  73.     cmp byte ptr es:[bx],$CF  {does int $67 point to iret?}
  74.     je @AbsentNoClose
  75.     mov dx,offset EmsDevice+1
  76.     mov ax,$3D02
  77.     int $21             {can we open EMM device?}
  78.     mov bx,ax
  79.     jc @AbsentNoClose
  80.     mov ax,$4400
  81.     int $21             {can we get its device properties?}
  82.     jc @Absent
  83.     and dx,$80          {does bit 7 = 1?}
  84.     jz @Absent
  85.     mov ax,$4407
  86.     int $21             {device ready for output?}
  87.     jc @Absent
  88.     or al,al
  89.     jz @Absent
  90.     push bx
  91.     mov ah,$30
  92.     int $21
  93.     pop bx
  94.     xchg ah,al
  95.     cmp ax,$030A
  96.     jb @Present
  97.     mov ax,$440A
  98.     int $21             {local device?}
  99.     jc @Present
  100.     and dx,$8000
  101.     jnz @Absent
  102. @Present:
  103.     mov ah,$3E           {close handle}
  104.     int $21
  105.     mov al,1
  106.     jmp @Done
  107. @Absent:
  108.     mov ah,$3E           {close handle}
  109.     int $21
  110. @AbsentNoClose:
  111.     xor ax,ax
  112. @Done:
  113.   end;
  114.  
  115.   function EmsPagesAvailable : LongInt; assembler;
  116.     {-Return Total pages in high word, Available pages in low word}
  117.   asm
  118.     mov ah, $42
  119.     int $67
  120.     or ah,ah
  121.     jnz @error
  122.     mov ax,bx     {available pages now in ax}
  123.     jmp @done
  124. @error:
  125.     xor ax,ax
  126.     mov dx,ax
  127. @done:
  128.   end;
  129.  
  130.   function EmsHandles(var PageMap : PageArray) : Word; assembler;
  131.     {-Return number of handles allocated and page map}
  132.   asm
  133.     mov ah,$4D
  134.     les di,PageMap
  135.     xor bx,bx
  136.     int $67
  137.     or ah,ah
  138.     mov ax,bx
  139.     jz @done
  140.     xor ax,ax
  141. @done:
  142.   end;
  143.  
  144.   function EmsVersion : Byte; assembler;
  145.     {-Return EMM version number}
  146.   asm
  147.     mov ah,$46
  148.     int $67
  149.     or ah,ah
  150.     jz @Done
  151.     xor al,al
  152. @Done:
  153.   end;
  154.  
  155.   procedure GetHandleName(Handle : Word; var Name : String); assembler;
  156.     {-Return name of EMS block, if any}
  157.   asm
  158.     mov dx,Handle
  159.     les di,Name
  160.     mov si,di         {save offset}
  161.     inc di            {point past length byte}
  162.     mov ax,$5300
  163.     int $67
  164.     mov al,0          {assume zero length}
  165.     or ah,ah
  166.     jnz @Done
  167.     mov cx,8
  168.     xor al,al
  169.     cld               {scan for null terminator}
  170.     repne scasb
  171.     mov al,8          {assume all 8 chars significant}
  172.     jne @Done
  173.     sub al,cl
  174.     dec al
  175. @Done:
  176.     mov es:[si],al    {store length byte}
  177.   end;
  178.  
  179.   function FreeEms(Handle : Word) : Byte; assembler;
  180.     {-Deallocate EMS handle}
  181.   asm
  182.     mov ah,$45
  183.     mov dx,Handle
  184.     int $67
  185.     mov al,ah
  186.   end;
  187.  
  188.   function RestorePageMap(Handle : Word) : Byte; assembler;
  189.     {-Restore page map}
  190.   asm
  191.     mov ah,$48
  192.     mov dx,HAndle
  193.     int $67
  194.     mov al,ah
  195.   end;
  196.  
  197. end.
  198.